package com.cwj.mansysback.service.impl;

import com.cwj.mansysback.dao.api.AccountDao;
import com.cwj.mansysback.dao.api.StudentDao;
import com.cwj.mansysback.dao.impl.AccountDaoImpl;
import com.cwj.mansysback.dao.impl.StudentDaoImpl;
import com.cwj.mansysback.entity.Pack;
import com.cwj.mansysback.entity.Student;
import com.cwj.mansysback.service.api.StudentService;

import java.util.List;

public class StudentServiceImpl implements StudentService {

    StudentDao studentDao = new StudentDaoImpl();

    AccountDao accDao = new AccountDaoImpl();


    @Override
    public boolean addStudent(Student stud) {

        boolean flag = accDao.addAccount(stud);

        if(!flag){
            return false;
        }

        return  studentDao.addStudent(stud.getAid(),stud.getSname(),stud.getSsex(),stud.getSage());
    }

    @Override
    public boolean deleteStudent(String sid) {
        boolean flag = accDao.deleteAccount(sid,Student.getRANK());

        if(!flag){
            return false;
        }

        return  studentDao.deleteStudent(sid);
    }

    @Override
    public Student selectStudent(String sid) {
        return studentDao.selectStudent(sid);
    }

    @Override
    public List<Student> selectCouStudent(String cid, int start, int len) {
        return studentDao.selectCouStudent(cid,start,len);
    }

    @Override
    public List<Student> selectStud(int start, int len) {
        return studentDao.selectStud(start,len);
    }

    @Override
    public List<Student> selectStud(int start, int len, String orderKey, boolean isAsc) {
        return studentDao.selectStud(start,len,orderKey,isAsc);
    }

    @Override
    public boolean updateStudent(String sid, String sname, boolean ssex, Integer sage) {
        return studentDao.updateStudent(sid,sname,ssex,sage);
    }

    @Override
    public Pack selectAllPack() {
        return studentDao.selectAllPack();
    }

    @Override
    public boolean updateStudent(Student stud) {
        return studentDao.updateStudent(stud.getAid(),stud.getSname(),stud.getSsex(),stud.getSage());
    }
}
